package demo1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(12);
        arrayList.add(123);
        arrayList.add(124);

        List<Integer> list = new ArrayList<>(arrayList);
        System.out.println(list);

        list.add(1,99);
        list.add(new Integer(99));
        System.out.println(list);
        list.addAll(arrayList);
        System.out.println(list);
        Integer a = list.remove(0);
        list.remove(new Integer(99));
        System.out.println(a);
        System.out.println(list);

        Integer b = list.get(0);
        list.set(0,9999);
        System.out.println(b);
        System.out.println(list);

        System.out.println(list.contains(9999));
        System.out.println(list.indexOf(9999));
        System.out.println(list.lastIndexOf(9999));
        List<Integer> list1 = list.subList(1, 3);
        list1.set(0,2346);
        System.out.println(list1);
        System.out.println(list);

        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
        for (Integer x: list) {
            System.out.print(x + " ");
        }
        System.out.println();

        //迭代器
        Iterator<Integer> it = list.listIterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }


    }
}
